package com.chen.hotel.controller;


import com.chen.hotel.Service.HotelService;
import com.chen.hotel.VO.ResultVO;
import com.chen.hotel.annotation.LoginToken;
import com.chen.hotel.domain.Hotel;
import com.chen.hotel.enums.AuthEnum;
import com.chen.hotel.utils.ResultVOUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@CrossOrigin
@RestController
@RequestMapping("/hotel")
public class HotelController {

    @Autowired
    private HotelService hotelService;

    /**
     * 创建酒店信息
     * @return
     */
    @PostMapping("")
    @LoginToken(auth = AuthEnum.SUPER)
    public ResultVO<Hotel> create(@RequestBody Hotel hotel){
        Hotel h = this.hotelService.create(hotel);
        return ResultVOUtil.success(h);
    }

    /**
     * 获取酒店信息
     */
    @GetMapping("/{id}")
    public ResultVO<Hotel> hotelById(@PathVariable Integer id){
        return ResultVOUtil.success(this.hotelService.findOne(id));
    }

    /**
     * 更新酒店信息
     */
    @PatchMapping("/{id}")
    @LoginToken(auth = AuthEnum.SUPER)
    public ResultVO<Hotel> update(@PathVariable Integer id, @RequestBody Hotel hotel){
        hotel.setId(id);
        return ResultVOUtil.success(this.hotelService.update(hotel));
    }

    /**
     * 删除酒店信息
     */
    @DeleteMapping("/{id}")
    @LoginToken(auth = AuthEnum.SUPER)
    public ResultVO delete(@PathVariable Integer id){
        this.hotelService.delete(id);
        return ResultVOUtil.success(null);
    }
}
